<?php
namespace App\Http\Controllers\Admin;

use App\Service\Admin\ShequService;
use Illuminate\Http\Request;

class ShequController extends BaseController
{
    //社区

    //列表
    public function index(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = ShequService::index($pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //省市区
    public function areaList(Request $request)
    {
        $pid = $request->post('pid', 0);
        $res = ShequService::areaListByPid($pid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', '');
        $pas['title'] = $request->post('title', '');
        $pas['map'] = $request->post('map', '');
        $pas['area_id'] = $request->post('area_id', '');
        if ($id) {
            $res = ShequService::modify($id, $pas);
        } else {
            $res = ShequService::add($pas);
        }
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ShequService::del($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}